package com.cn.jdia.dc.utils.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DBManager4Oracle {

	public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";

	private static DBManager4Oracle per = null;

	private Connection conn = null;
	private Statement stmt = null;

	public DBManager4Oracle() {

	}

	public static DBManager4Oracle createInstance() {
		if (per == null) {
			per = new DBManager4Oracle();
			per.initDB();
		}
		return per;
	}

	public void initDB() {
		try {
			Class.forName(DRIVER);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public int connectDB(String url, String user, String pass) {
		try {
			conn = DriverManager.getConnection(url, user, pass);
			stmt = conn.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
		return 0;
	}

	public void closeDB() {
		try {
			if (stmt != null) {
				stmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
